package cn.cxq.learning.stack;

public class ArrayStack {

    private double[] stack;
    private int maxSize;
    private int top;

    public ArrayStack(int num) {
        this.maxSize = num;
        this.stack = new double[this.maxSize];
        top = -1;
    }

    public boolean isFull(){
        return this.top == this.maxSize -1;
    }

    public boolean isEmpty(){
        return this.top == -1;
    }

    public void push(double value){
        if (isFull()){
            System.out.println("栈满~~~");
            return;
        }
        this.stack[++ this.top] = value;
    }

    public double pop(){
        if (isEmpty()){
            throw new RuntimeException("栈空~~~");
        }

        return this.stack[this.top --];
    }

    public void list(){
        System.out.println("栈中数据：");

        if (isEmpty()){
            throw new RuntimeException("栈空~~~");
        }

        for (int i = 0; i < this.top; i++) {
            System.out.println(stack[i]);
        }
    }
}
